/** @format */

import { computed } from 'vue'
import { CACHE_KEY } from '../contants/configCont'
import { useEntity } from './useEntity'

const { content, getData } = useEntity({
  cacheKey: CACHE_KEY.openInfo,
  path: 'open.json',
  cacheTime: 60 * 60 * 1000
})

const list = computed(() => content.value)
const getRandomItem = () => {
  if (!list.value || !list.value.length) return null
  const index = Math.floor(Math.random() * list.value.length)
  console.log('test index', index, list.value.length)
  return list.value[index]
}

export const useOpen = () => {
  getData()

  return {
    list,
    getRandomItem,
  }
}
